package com.sdhs.web.controller.contract;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.system.domain.GcContractParty;
import com.sdhs.system.service.IGcContractPartyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合同子表-相对方Controller
 *
 * @author add
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/system/party")
public class GcContractPartyController extends BaseController
{
    @Autowired
    private IGcContractPartyService gcContractPartyService;

    /**
     * 查询合同子表-相对方列表
     */
    @PreAuthorize("@ss.hasPermi('system:party:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcContractParty gcContractParty)
    {
        startPage();
        List<GcContractParty> list = gcContractPartyService.selectGcContractPartyList(gcContractParty);
        return getDataTable(list);
    }

    /**
     * 导出合同子表-相对方列表
     */
    @PreAuthorize("@ss.hasPermi('system:party:export')")
    @Log(title = "合同子表-相对方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcContractParty gcContractParty)
    {
        List<GcContractParty> list = gcContractPartyService.selectGcContractPartyList(gcContractParty);
        ExcelUtil<GcContractParty> util = new ExcelUtil<GcContractParty>(GcContractParty.class);
        util.exportExcel(response, list, "合同子表-相对方数据");
    }

    /**
     * 获取合同子表-相对方详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:party:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gcContractPartyService.selectGcContractPartyById(id));
    }

    /**
     * 新增合同子表-相对方
     */
    @PreAuthorize("@ss.hasPermi('system:party:add')")
    @Log(title = "合同子表-相对方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcContractParty gcContractParty)
    {
        return toAjax(gcContractPartyService.insertGcContractParty(gcContractParty));
    }

    /**
     * 修改合同子表-相对方
     */
    @PreAuthorize("@ss.hasPermi('system:party:edit')")
    @Log(title = "合同子表-相对方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcContractParty gcContractParty)
    {
        return toAjax(gcContractPartyService.updateGcContractParty(gcContractParty));
    }

    /**
     * 删除合同子表-相对方
     */
    @PreAuthorize("@ss.hasPermi('system:party:remove')")
    @Log(title = "合同子表-相对方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gcContractPartyService.deleteGcContractPartyByIds(ids));
    }
}
